function[IRF_convert]=IRF_convert(IRF,N,hor,tcode)

IRF_convert=zeros(size(IRF));

for i=1:N
     if tcode(1,i)==1||tcode(1,i)==4;
        IRF_convert(i,:)=IRF(i,:); 
     end
     
     if tcode(1,i)==2||tcode(1,i)==5;
        IRF_convert(i,:)=cumsum(IRF(i,:)); 
     end
     
     if tcode(1,i)==3||tcode(1,i)==6;
        for i_diff=1:hor+1;
           if i_diff==1;
           IRF_convert(i,i_diff)= IRF(i,i_diff);          
           end
           if i_diff==2;
           IRF_convert(i,i_diff)=2*IRF_convert(i,i_diff)+IRF(i,i_diff);          
           end
           if i_diff>=3;
           IRF_convert(i,i_diff)=2*IRF_convert(i,i_diff-1)-IRF_convert(i,i_diff-2)+IRF(i,i_diff);           
           end
        end         
    end
end


end